@echo off
set current_dir=%~dp0%

set nghttp2_version=1.41.0
set nghttp2_dirname=nghttp2-%nghttp2_version%
set nghttp2_src_dir=%current_dir%%nghttp2_dirname%
set nghttp2_lib=%nghttp2_src_dir%\lib

echo "nghttp2 version: %nghttp2_version%"
echo "nghttp2 src dir: %nghttp2_src_dir%"

call "%VS100COMNTOOLS%vsvars32.bat"

rem -----------------------------------------------------------------
rem 输出目录
set build_output_root=%current_dir%build-output-%nghttp2_dirname%
if exist %build_output_root% ( rmdir /S /Q %build_output_root% )
mkdir %build_output_root%
mkdir %build_output_root%\include\nghttp2
mkdir %build_output_root%\lib
mkdir %build_output_root%\lib\Release
mkdir %build_output_root%\lib\Debug

rem -----------------------------------------------------------------
rem 解压代码
if exist %nghttp2_src_dir% ( rmdir /S /Q %nghttp2_src_dir% )
tar -xf %nghttp2_src_dir%.zip

cd  %nghttp2_src_dir%
set cmake_exe="%CMAKE_BIN%\cmake.exe"
%cmake_exe% -G "Visual Studio 10 2010" -DENABLE_LIB_ONLY=ON -DENABLE_STATIC_LIB=ON -DENABLE_STATIC_CRT=ON

call:build_nghttp Release
xcopy /S /Y %nghttp2_lib%\includes\nghttp2\*.h %build_output_root%\include\nghttp2

call:build_nghttp Debug

echo "output in %build_output_root%"
pause
exit /b 0

:build_nghttp
set build_config=%~1
echo build for %build_config%
%cmake_exe% --build . --config %build_config% --target nghttp2_static
copy /Y %nghttp2_lib%\%build_config%\nghttp2.lib %build_output_root%\lib\%build_config%\nghttp2_static.lib
goto:eof